package com.lagou.server;

import java.io.*;

public class Response {
    private OutputStream outputStream;

    public Response() {
    }

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void output(String content) throws IOException {

        outputStream.write(content.getBytes());
    }
    //根据url获取静态资源绝对路径，最终读取资源输出
    public void outPutHtml(String path) throws IOException {
        String absoluteResource=StaticResourceUtil.getAbsolutePath(path);
        File  file=new File(absoluteResource);
        if(file.exists() && file.isFile()){
            StaticResourceUtil.outputStaticResource(new FileInputStream(absoluteResource),outputStream);
        }else{
            output(HttpProtocoUtil.getHttpHeader404());
        }
    }
}
